package com.jinsi.controller;

import com.jinsi.pojo.TreeData;
import com.jinsi.service.impl.ScClassesServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class ClassesTreeController {
    @Autowired
    private ScClassesServiceImpl service;

    @ResponseBody
    @RequestMapping("/getTree")
    public List<TreeData> getTree(){
        List<TreeData> tree = service.getTree(0);
        return tree;
    }

    @ResponseBody
    @RequestMapping("/addClassesTree")
    public Map<String,String> addClassesTree(Integer pid, String title,String classesLevels){
        Map<String, String> map = new HashMap<>();
        try {
            service.addClassesTree(pid,title,classesLevels);
            map.put("state","200");
        } catch (Exception e) {
            e.printStackTrace();
            map.put("state","400");
        }

        return map;
    }

    @ResponseBody
    @RequestMapping("/upClassesTree")
    public Map<String,String> upClassesTree(Integer id, String title,String classesLevels){
        Map<String, String> map = new HashMap<>();
        try {
            service.upClassesTree(id,title,classesLevels);
            map.put("state","200");
        } catch (Exception e) {
            e.printStackTrace();
            map.put("state","400");
        }
        return map;
    }

    @ResponseBody
    @RequestMapping("/deClassesTree")
    public Map<String,String> deClassesTree(Integer id){

        Map<String, String> map = new HashMap<>();
        try {
            service.deClassesTree(id);
            map.put("state","200");
        } catch (Exception e) {
            e.printStackTrace();
            map.put("state","400");
        }
        return map;
    }
}
